ARM		:= arm-linux-gnueabihf-

GCC 	:= $(ARM)gcc
LD		:= $(ARM)ld
OBJCOPY := $(ARM)objcopy
OBJDUMP := $(ARM)objdump

NAME	:= epit
NAMEOBJ := obj/$(NAME)

INCDIRS := 	imx6ul		\
		   	project		\
		   	bsp/led		\
		   	bsp/delay	\
		   	bsp/clk		\
			bsp/beep	\
			bsp/key		\
			bsp/gpio	\
			bsp/int		\
			bsp/exit	\
			bsp/epit

SRCDIRS :=	project		\
			bsp/led		\
			bsp/delay	\
			bsp/clk		\
			bsp/beep	\
			bsp/key		\
			bsp/gpio	\
			bsp/int		\
			bsp/exit	\
			bsp/epit

INCLUDE := $(patsubst %, -I %, $(INCDIRS))

SFILE	:= $(foreach dir, $(SRCDIRS), $(wildcard $(dir)/*.s))
CFILE	:= $(foreach dir, $(SRCDIRS), $(wildcard $(dir)/*.c))

SFILENDIR := $(notdir $(SFILE))
CFILENDIR := $(notdir $(CFILE))

SOBJS	:= $(patsubst %, obj/%, $(SFILENDIR:.s=.o))
COBJS	:= $(patsubst %, obj/%, $(CFILENDIR:.c=.o))
OBJS	:= $(SOBJS) $(COBJS)

VPATH := $(SRCDIRS)

$(NAMEOBJ).bin : $(OBJS)
	$(LD) -Timx6ul.lds $^ -o $(NAMEOBJ).elf
	$(OBJCOPY) -O binary -S -g $(NAMEOBJ).elf $@
	$(OBJDUMP) -D $(NAMEOBJ).elf > $(NAMEOBJ).dis

$(SOBJS) : obj/%.o : %.s
	$(GCC) -g -c $(INCLUDE) $< -o $@

$(COBJS) : obj/%.o : %.c
	$(GCC) -g -c $(INCLUDE) $< -o $@ 

print:
	@echo $(SOBJS)
	@echo $(INCLUDE)
	@echo $(NAMEOBJ)

clear:
	rm -rf $(OBJS) $(NAMEOBJ).bin $(NAMEOBJ).elf $(NAMEOBJ).dis load.imx